<template>
  <div>
    <el-dialog
      :visible.sync="dialog.add"
      :close-on-click-modal="false"
      title="添加"
      width="80%"
      append-to-body
      @closed="dialogClosed('addForm')"
    >
      <el-form ref="addForm" :model="form" label-width="120px" :rules="validateRules">
        <el-row>
          <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
	<el-form-item label="类型名称" prop="title">
	<el-input v-model="form.title" placeholder="请输入类型名称" clearable/>
</el-form-item>
	</el-col>
<el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
	<el-form-item label="类型代码" prop="code">
	<el-input v-model="form.code" placeholder="请输入类型代码" clearable/>
</el-form-item>
	</el-col>
<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
	<el-form-item label="类型描述" prop="description">
	<el-input type="textarea" v-model="form.description" placeholder="请输入类型描述" clearable/>
</el-form-item>
	</el-col>

        </el-row>
      </el-form>
      <div slot="footer">
        <el-button @click="dialog.add = false">取消</el-button>
        <el-button type="primary" @click="add" :loading="loading.add">添加</el-button>
      </div>
    </el-dialog>
    <el-dialog
      :visible.sync="dialog.edit"
      :close-on-click-modal="false"
      title="修改"
      width="80%"
      append-to-body
      @closed="dialogClosed('editForm')"
    >
      <el-form ref="editForm" :model="form" label-width="120px" :rules="validateRules">
        <el-row>
          <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
	<el-form-item label="类型名称" prop="title">
	<el-input v-model="form.title" placeholder="请输入类型名称" clearable/>
</el-form-item>
	</el-col>
<el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
	<el-form-item label="类型代码" prop="code">
	<el-input v-model="form.code" placeholder="请输入类型代码" clearable/>
</el-form-item>
	</el-col>
<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
	<el-form-item label="类型描述" prop="description">
	<el-input type="textarea" v-model="form.description" placeholder="请输入类型描述" clearable/>
</el-form-item>
	</el-col>

        </el-row>
      </el-form>
      <div slot="footer">
        <el-button @click="dialog.edit = false">取消</el-button>
        <el-button type="primary" @click="edit" :loading="loading.edit">修改</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import * as utils from '@/utils/utils'
import * as ResponseStatus from '@/utils/response-status'
import UploadImage from '@/components/Upload/UploadImage'
import Tinymce from '@/components/Tinymce'
const resUrl = process.env.VUE_APP_RES_URL
export default {
  name: 'AdvertisementTypeAddEdit',
  components: {
    UploadImage,
    Tinymce
  },
  data() {
    return {
      dialog: {
        add: false,
        edit: false
      },
      loading: {
        add: false,
        edit: false
      },
      form: {
        title: undefined,
code: undefined,
description: undefined,

      },
      validateRules: {
        title: [
{type: 'string', required: true, message: '此项为必须项', trigger: 'blur'},
{type: 'string', min: 1, max: 20, message: '必须1-20个字符', trigger: 'blur'}
],
code: [
{type: 'string', required: true, message: '此项为必须项', trigger: 'blur'},
{type: 'string', min: 1, max: 20, message: '必须1-20个字符', trigger: 'blur'}
],
description: [
{type: 'string', min: 1, max: 500, message: '必须1-500个字符', trigger: 'blur'}
],

      },
      dataDictCodes: [],
      selects: {

      },
      resUrl: resUrl
    }
  },
  computed: {},
  mounted() {
    this.initDataDict()
    utils
      .getDataDict(this.dataDictCodes)
      .then(response => {
        if (response) {

        }
      })
      .catch(error => {})
  },
  methods: {
    initDataDict() {

    },
    dialogClosed(formRef) {
      this.$refs[formRef].resetFields()
      for (let key in this.form) {
        this.form[key] = undefined
      }
    },
    add() {
      this.$emit('add')
    },
    edit() {
      this.$emit('edit')
    },
    /** 触发父组件展示关联表数据的搜索对话框 */
    showJoinSearch(options) {
      this.$emit('showJoinSearchDialog', options)
    },
    imgUploadSuccess(formProp, url) {
      this.form[formProp] = url
    },
    imgRemoveSuccess(formProp) {
      this.form[formProp] = undefined
    }
  }
}
</script>

<style>
</style>